package com.example.homework.Pojo;

import org.springframework.stereotype.Component;

public class Result {
    private static final String SUCCESS_CODE = "100000";
    private static final String ERROR_CODE = "100001";
    private static final String SUCCESS_MESSAGE = "SUCCESS";
    private static final String ERROR_MESSAGE = "系统异常";
    private String code;
    private String message;
    private Object data;
    private boolean success;

    public Result() {}

    public Result(String code, String message, Object data, boolean success) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.success = success;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(String data) { this.data = data; }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }
    public static Result send(){
        Result result=new Result();
        result.code=SUCCESS_CODE;
        result.message=SUCCESS_MESSAGE;
        result.success=true;
        return result;
    }
    public static Result send(Object data){
        Result result=new Result();
        result.code=SUCCESS_CODE;
        result.data=data;
        result.message=SUCCESS_MESSAGE;
        result.success=true;
        return result;
    }
    public static Result error(){
        Result result=new Result();
        result.code=ERROR_CODE;
        result.message=ERROR_MESSAGE;
        result.success=false;
        return result;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", date='" + data + '\'' +
                ", success=" + success +
                '}';
    }
}
